package org.anyline.simiple;


import org.anyline.pdf.util.PDFUtil;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;


@SpringBootApplication

public class PdfApplication  {

	public static void main(String[] args) throws Exception {
		File file = new File("D:\\order1.pdf");
		File copy = new File("D:\\order_copy.pdf");
 		String text = PDFUtil.read(file);
		System.out.println(text);

		List<String> list = PDFUtil.reads(file);
		int page = 0;
		for(String str : list){
			System.out.println("-----------" + page++ + "------------");
			System.out.println(str);
			System.out.println("===============" + page + "====================");
		}
		remove(file, copy, 5);

	}

	public static void remove(File file, File target, int ... pages) throws Exception{
		PDDocument doc = null;
		//输入流
		InputStream is = Files.newInputStream(file.toPath());
		try {
			doc = PDDocument.load(is);
			for(int page:pages){
				doc.removePage(page);
			}
			doc.save(target);
		} finally {
			is.close();
			if (doc != null) {
				// 关闭PDF Document
				doc.close();
			}
		}
	}
}
